package yuejian_07.yuejian_07.model;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import yuejian_07.yuejian_07.RetrofitListener;
<<<<<<< HEAD
import yuejian_07.yuejian_07.javabean.Show;
=======
import yuejian_07.yuejian_07.activity.EnrollActActivity;
import yuejian_07.yuejian_07.activity.EnrollTrainActivity;
import yuejian_07.yuejian_07.javabean.EnterActBean;
import yuejian_07.yuejian_07.javabean.EnterTrainBean;
>>>>>>> 9cbb853725830abfea6e866ce1cbf3c925de3bcd
import yuejian_07.yuejian_07.javabean.User;
import yuejian_07.yuejian_07.service.UserService;

/**
 * Created by Shuaier on 2017/4/19.
 */

public class UserModel {
    private Retrofit retrofit;
    public UserModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/neu1_yuejian/index.php/Api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    /*public Call login(String str_user,String str_password){
        UserService userService=retrofit.create(UserService.class);
        return userService.userLogin(str_user,str_password);
    }*/

    public void Login(String username, String password, final RetrofitListener listener){
        UserService userService=retrofit.create(UserService.class);
        Call call=userService.userLogin(username,password);
        Callback<User> callback=new Callback<User>(){
            @Override
            public void onResponse(Call<User> call, Response<User> response){
                User user = response.body();
               listener.onSuccess(user);

            }
            @Override
            public  void onFailure(Call<User> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
<<<<<<< HEAD
    public void getUserById(int User_id, final RetrofitListener listener){
=======
    //获取用户详情
    public void getUserById(int User_id, final EnrollActActivity listener){
>>>>>>> 9cbb853725830abfea6e866ce1cbf3c925de3bcd
        UserService userService=retrofit.create(UserService.class);
        Call call=userService.getUserById(User_id);
        Callback<User> callback=new Callback<User>(){
            @Override
            public void onResponse(Call<User> call, Response<User> response){
<<<<<<< HEAD
=======

                listener.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<User> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    public void getUserById(int User_id, final EnrollTrainActivity listener){
        UserService userService=retrofit.create(UserService.class);
        Call call=userService.getUserById(User_id);
        Callback<User> callback=new Callback<User>(){
            @Override
            public void onResponse(Call<User> call, Response<User> response){

                listener.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<User> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
>>>>>>> 9cbb853725830abfea6e866ce1cbf3c925de3bcd

                listener.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<User> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }




//    public Call reg(String str_user,String str_password,String str_address,
//                    String str_mobilenum,String str_comment){
//        UserService userService=retrofit.create(UserService.class);
//        return userService.userRegister(str_user,str_password,str_mobilenum,str_address,str_comment);
//    }
    public Call getUserById(int user_id){
        UserService userService=retrofit.create(UserService.class);
        return userService.getUserById(user_id);
    }
    //获取用户信息
    public Call<User> getUserInfo(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getUserInfo(user_id);
    }



//    public Call editInfo(int uid,String uname,String upass,String phonenum,String address){
//        UserService userService=retrofit.create(UserService.class);
//        return userService.getUpdateUserById(uid, uname, upass, phonenum, address);
//    }

    public Call<User> getUserInfo(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getUserInfo(user_id);
    }
    public Call<User> edituser(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.edituser(user_id);
    }



    public Call<List<Show>> getMypostlist(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMypostlist(user_id);
    }

    public Call<User> updateuser(int user_id, String user_name, String user_password, String user_phone) {
        UserService userService = retrofit.create(UserService.class);
        return userService.updateuser(user_id, user_name, user_password, user_phone);
    }
    //查看我的活动订单列表
    public Call<List<EnterActBean>> getMyActOrderlist(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyActOrderlist(user_id);
    }
    //查看我的培训订单列表
    public Call<List<EnterTrainBean>> getMyTrainOrderlist(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyTrainOrderlist(user_id);
    }





}